package test.designmode.delegatecomm;

import java.lang.reflect.*;

public class MessageOccuredEventHandler {
	Object target;
	String methodName;
	Method method = null;

	public MessageOccuredEventHandler(Object target, String methodName) {
		this.target = target;
		this.methodName = methodName;
		Method[] methods = target.getClass().getMethods();
		for (int _i = 0; _i < methods.length; _i++) {
			Method m = methods[_i];
			if (m.getName().equals(methodName)) {
				method = m;
				break;
			}
		}
	}

	public void dnInvokeDelegate(Object sender, String messageText) {
		try {
			Object[] params = new Object[2];
			params[0] = sender;
			params[1] = messageText;
			if (method != null)
				method.invoke(target, params);
		} catch (Throwable t) {
			t.printStackTrace();
		}
	}
}